package wili.b1;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import wili.a.Obj9;
import wili.c.Ca;
import wili.c.File9a;

class b1_tools_main {
	/**
	 * eg. 当加载 SalesDoc.detailView.json时，会加载其中的 viewId:指向的细节json. 本方法找到这些json,
	 * 打印其文件名。
	 *
	 * @param view
	 */
	public static void findJsonFileNames_from_DetailView(String msg, Object view) {
		int opt = 1;
		if (!msg.equals("SalesDoc"))
			return;
		if ("".isEmpty() || opt == 2)
			return;
		// FindJsonFileFromDetailView.java
		String cname = view.getClass().getSimpleName();
		Ca.asert(cname.equals("DetailView"), cname);
		Obj9.find("viewId", "", view);
	}

	static Object start() {
		int opt = 1;
		opt = 2;
		// opt = 3;
		switch (opt) {
		case 1:
			return copyDir_b1Client();
		case 12:
			return copyDir_b1Client();
		case 2:
			return findTexts_fromDir();
		case 21:
			return findTexts_fromDir();
		case 3:
			return insertIncNum_to_files(1, 1);
		default:
			return "";
		}
	}

	static Object insertIncNum_to_files(int insert, int opt) {
		if ("asdf".isEmpty()) {
			String cmd = Ca.readCmdLine("add number(a) or remove number(r)?");
			if (!cmd.equals("a") && !cmd.equals("r")) {
				Ca.log(1, "usage: input 'a' or 'r'");
				return "";
			}
			// insert = cmd.equals("a");
		}
		InsertIncNumToFile9.INC[0] = 0;
		if (opt == 1)
			// insertIncNum_to_all_jsonFile(insert, "(\"(label|text)\": \"[^\"]+\\})\"",
			// r("$1;`;`\""));
			InsertIncNumToFile9.insertIncNum_to_all_jsonFile(insert == 1, "\"(label|text)\":\\s*\"([^\"]+)\"",
					r("\"$1\": \"$2;`;`\""));
		else if (opt == 2)
			InsertIncNumToFile9.insertIncNum_to_all_propertiesFile(insert == 1, "([^=#\r\n]+)=([^=\r\n]+)",
					r("$1=$2;`;`"));
		else if (opt == 3)
			InsertIncNumToFile9.insertIncNum_to_all_xmlFile(insert == 1, "", "");
		Ca.log(1, "all fileNum=" + InsertIncNumToFile9.allNum + ", updateNum=" + InsertIncNumToFile9.updateNum + ".");
		return "";
	}

	static String r(String st) {
		return st.replaceFirst("`", InsertIncNumToFile9.MARK);
	}

	static Object findTexts_fromDir() {
		File root = Cont.fileOf("C:\\Perforce", "BUSMB_B1\\SBO\\dev\\Source\\WebClient\\node");
		// File9a.findTexts_fromDir(root, "Document Number,Customer Code,Customer
		// Name,Posting Date,Delivery Date,Document Total,Status".split("\\s*,\\s*"));
		return File9a.findTexts_fromDir(root, "OK,Cancel,Reset".split("\\s*,\\s*"));
	}

	public static void main(String[] args) {
		start();
	}

	public static String copyDir_b1Client() {
		// 15346个文件
		List<String[]> list;
		list = Arrays.asList(new String[] {
				//
				"C:/Perforce/" + InsertIncNumToFile9a.chgList + "/BUSMB_B1/SBO/dev/Source/WebClient/java", //
				"C:/t/" + InsertIncNumToFile9a.chgList },
				//
				new String[] {
						"C:/Perforce/" + InsertIncNumToFile9a.chgList + "/BUSMB_B1/SBO/dev/Source/WebClient/node", //
						"C:/t/" + InsertIncNumToFile9a.chgList });
		for (String[] ft : list) {
			File from = new File(ft[0]), to = new File(ft[1]);
			// int ret = File9a.copyDir_bySufix(from, to, true, ".java", ".json",
			// "pom.xml",".properties");
			int ret = File9a.copyDir_bySufix(from, to, true, ".json", "pom.xml", ".properties");
			Ca.log(" " + ret + " file copied.");
		}
		return "";
	}
}
